package demo.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import demo.common.Result;
import demo.entity.Allr;
import demo.entity.Yuce;
import demo.mapper.CalulateMapper;
import demo.mapper.CalulateMapper2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin(maxAge = 36000)
@RestController
@RequestMapping("/Calculate")
public class Calculate {
  @Resource
  CalulateMapper calulateMapper;
  @Resource
  CalulateMapper2 calulateMapper2;

  @GetMapping("/2")
  public Result<?> calculate(
    @RequestParam(defaultValue = "") String unname,
    @RequestParam(defaultValue = "") String maname) {
    System.out.println("学校"+unname+"专业"+maname);
    Map<String,Object>  columnMap = new HashMap<>();
    columnMap.put("unname",unname);
    columnMap.put("maname",maname);
    List<Allr> allr = calulateMapper2.selectByMap(columnMap);
    return Result.success(allr);
  }
  @GetMapping
  public Result<?> yuce(@RequestParam(defaultValue = "1") Integer pageNum,
                        @RequestParam(defaultValue = "10") Integer pageSize,
                        @RequestParam(defaultValue = "") String search){
    LambdaQueryWrapper<Yuce> wrapper = Wrappers.<Yuce>lambdaQuery();
    if(StrUtil.isNotBlank(search)) {
      wrapper.like(Yuce::getUnname , search);
    }
    Page<Yuce> Page = calulateMapper.selectPage(new Page<>(pageNum,pageSize),wrapper);
    return Result.success(Page);
  }
}
